﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using HYSoft.IDAL;
using Maticsoft.DBUtility;//Please add references
namespace HYSoft.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:gprsNodeLog
	/// </summary>
	public partial class gprsNodeLog:IgprsNodeLog
	{
		public gprsNodeLog()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("index", "gprsNodeLog"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int index)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from gprsNodeLog");
			strSql.Append(" where index=@index");
			SqlParameter[] parameters = {
					new SqlParameter("@index", SqlDbType.Int,4)
			};
			parameters[0].Value = index;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HYSoft.Model.gprsNodeLog model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into gprsNodeLog(");
			strSql.Append("mac,wendu,dianchi,gongdian,dianliang,chuanganqi,time,chartime,sendmsg,jingbao,intvalue,charvalue,year,mtransmode)");
			strSql.Append(" values (");
			strSql.Append("@mac,@wendu,@dianchi,@gongdian,@dianliang,@chuanganqi,@time,@chartime,@sendmsg,@jingbao,@intvalue,@charvalue,@year,@mtransmode)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@mac", SqlDbType.Int,4),
					new SqlParameter("@wendu", SqlDbType.Int,4),
					new SqlParameter("@dianchi", SqlDbType.Int,4),
					new SqlParameter("@gongdian", SqlDbType.Int,4),
					new SqlParameter("@dianliang", SqlDbType.Int,4),
					new SqlParameter("@chuanganqi", SqlDbType.Int,4),
					new SqlParameter("@time", SqlDbType.Int,4),
					new SqlParameter("@chartime", SqlDbType.VarChar,200),
					new SqlParameter("@sendmsg", SqlDbType.Int,4),
					new SqlParameter("@jingbao", SqlDbType.Int,4),
					new SqlParameter("@intvalue", SqlDbType.Int,4),
					new SqlParameter("@charvalue", SqlDbType.VarChar,250),
					new SqlParameter("@year", SqlDbType.Int,4),
					new SqlParameter("@mtransmode", SqlDbType.VarChar,250)};
			parameters[0].Value = model.mac;
			parameters[1].Value = model.wendu;
			parameters[2].Value = model.dianchi;
			parameters[3].Value = model.gongdian;
			parameters[4].Value = model.dianliang;
			parameters[5].Value = model.chuanganqi;
			parameters[6].Value = model.time;
			parameters[7].Value = model.chartime;
			parameters[8].Value = model.sendmsg;
			parameters[9].Value = model.jingbao;
			parameters[10].Value = model.intvalue;
			parameters[11].Value = model.charvalue;
			parameters[12].Value = model.year;
			parameters[13].Value = model.mtransmode;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HYSoft.Model.gprsNodeLog model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update gprsNodeLog set ");
			strSql.Append("mac=@mac,");
			strSql.Append("wendu=@wendu,");
			strSql.Append("dianchi=@dianchi,");
			strSql.Append("gongdian=@gongdian,");
			strSql.Append("dianliang=@dianliang,");
			strSql.Append("chuanganqi=@chuanganqi,");
			strSql.Append("time=@time,");
			strSql.Append("chartime=@chartime,");
			strSql.Append("sendmsg=@sendmsg,");
			strSql.Append("jingbao=@jingbao,");
			strSql.Append("intvalue=@intvalue,");
			strSql.Append("charvalue=@charvalue,");
			strSql.Append("year=@year,");
			strSql.Append("mtransmode=@mtransmode");
			strSql.Append(" where index=@index");
			SqlParameter[] parameters = {
					new SqlParameter("@mac", SqlDbType.Int,4),
					new SqlParameter("@wendu", SqlDbType.Int,4),
					new SqlParameter("@dianchi", SqlDbType.Int,4),
					new SqlParameter("@gongdian", SqlDbType.Int,4),
					new SqlParameter("@dianliang", SqlDbType.Int,4),
					new SqlParameter("@chuanganqi", SqlDbType.Int,4),
					new SqlParameter("@time", SqlDbType.Int,4),
					new SqlParameter("@chartime", SqlDbType.VarChar,200),
					new SqlParameter("@sendmsg", SqlDbType.Int,4),
					new SqlParameter("@jingbao", SqlDbType.Int,4),
					new SqlParameter("@intvalue", SqlDbType.Int,4),
					new SqlParameter("@charvalue", SqlDbType.VarChar,250),
					new SqlParameter("@year", SqlDbType.Int,4),
					new SqlParameter("@mtransmode", SqlDbType.VarChar,250),
					new SqlParameter("@index", SqlDbType.Int,4)};
			parameters[0].Value = model.mac;
			parameters[1].Value = model.wendu;
			parameters[2].Value = model.dianchi;
			parameters[3].Value = model.gongdian;
			parameters[4].Value = model.dianliang;
			parameters[5].Value = model.chuanganqi;
			parameters[6].Value = model.time;
			parameters[7].Value = model.chartime;
			parameters[8].Value = model.sendmsg;
			parameters[9].Value = model.jingbao;
			parameters[10].Value = model.intvalue;
			parameters[11].Value = model.charvalue;
			parameters[12].Value = model.year;
			parameters[13].Value = model.mtransmode;
			parameters[14].Value = model.index;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int index)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from gprsNodeLog ");
			strSql.Append(" where index=@index");
			SqlParameter[] parameters = {
					new SqlParameter("@index", SqlDbType.Int,4)
			};
			parameters[0].Value = index;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string indexlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from gprsNodeLog ");
			strSql.Append(" where index in ("+indexlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HYSoft.Model.gprsNodeLog GetModel(int index)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 index,mac,wendu,dianchi,gongdian,dianliang,chuanganqi,time,chartime,sendmsg,jingbao,intvalue,charvalue,year,mtransmode from gprsNodeLog ");
			strSql.Append(" where index=@index");
			SqlParameter[] parameters = {
					new SqlParameter("@index", SqlDbType.Int,4)
			};
			parameters[0].Value = index;

			HYSoft.Model.gprsNodeLog model=new HYSoft.Model.gprsNodeLog();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HYSoft.Model.gprsNodeLog DataRowToModel(DataRow row)
		{
			HYSoft.Model.gprsNodeLog model=new HYSoft.Model.gprsNodeLog();
			if (row != null)
			{
				if(row["index"]!=null && row["index"].ToString()!="")
				{
					model.index=int.Parse(row["index"].ToString());
				}
				if(row["mac"]!=null && row["mac"].ToString()!="")
				{
					model.mac=int.Parse(row["mac"].ToString());
				}
				if(row["wendu"]!=null && row["wendu"].ToString()!="")
				{
					model.wendu=int.Parse(row["wendu"].ToString());
				}
				if(row["dianchi"]!=null && row["dianchi"].ToString()!="")
				{
					model.dianchi=int.Parse(row["dianchi"].ToString());
				}
				if(row["gongdian"]!=null && row["gongdian"].ToString()!="")
				{
					model.gongdian=int.Parse(row["gongdian"].ToString());
				}
				if(row["dianliang"]!=null && row["dianliang"].ToString()!="")
				{
					model.dianliang=int.Parse(row["dianliang"].ToString());
				}
				if(row["chuanganqi"]!=null && row["chuanganqi"].ToString()!="")
				{
					model.chuanganqi=int.Parse(row["chuanganqi"].ToString());
				}
				if(row["time"]!=null && row["time"].ToString()!="")
				{
					model.time=int.Parse(row["time"].ToString());
				}
				if(row["chartime"]!=null)
				{
					model.chartime=row["chartime"].ToString();
				}
				if(row["sendmsg"]!=null && row["sendmsg"].ToString()!="")
				{
					model.sendmsg=int.Parse(row["sendmsg"].ToString());
				}
				if(row["jingbao"]!=null && row["jingbao"].ToString()!="")
				{
					model.jingbao=int.Parse(row["jingbao"].ToString());
				}
				if(row["intvalue"]!=null && row["intvalue"].ToString()!="")
				{
					model.intvalue=int.Parse(row["intvalue"].ToString());
				}
				if(row["charvalue"]!=null)
				{
					model.charvalue=row["charvalue"].ToString();
				}
				if(row["year"]!=null && row["year"].ToString()!="")
				{
					model.year=int.Parse(row["year"].ToString());
				}
				if(row["mtransmode"]!=null)
				{
					model.mtransmode=row["mtransmode"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select index,mac,wendu,dianchi,gongdian,dianliang,chuanganqi,time,chartime,sendmsg,jingbao,intvalue,charvalue,year,mtransmode ");
			strSql.Append(" FROM gprsNodeLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" index,mac,wendu,dianchi,gongdian,dianliang,chuanganqi,time,chartime,sendmsg,jingbao,intvalue,charvalue,year,mtransmode ");
			strSql.Append(" FROM gprsNodeLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM gprsNodeLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.index desc");
			}
			strSql.Append(")AS Row, T.*  from gprsNodeLog T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "gprsNodeLog";
			parameters[1].Value = "index";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

